import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_plugin_tts/flutter_plugin_tts.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:intl/intl.dart';

///路由
urlPush(BuildContext context, String url) {
  Uri u = Uri.parse(url);
  if (u.queryParameters.isNotEmpty) {
    print("参数----------->${u.queryParameters}");
    Navigator.of(context).pushNamed(u.authority, arguments: u.queryParameters);
  } else {
    Navigator.of(context).pushNamed(u.authority);
  }
}

///清除两个页面之间的全部栈
jump(BuildContext context, {Widget widget, String name}) {
  Navigator.push(
      context,
      MaterialPageRoute(
        builder: (context) => widget,
        settings: RouteSettings(name: name),
      ));
}

///吐司
toast(String title) {
  Fluttertoast.showToast(
      msg: title,
      toastLength: Toast.LENGTH_SHORT,
      gravity: ToastGravity.CENTER,
      timeInSecForIosWeb: 1,
      backgroundColor: Color.fromARGB(204, 0, 0, 0),
//      backgroundColor: Color(0xffF5F5F5),
      textColor: Color(0xffFFFFFF),
      fontSize: 16.0);
}

///格式化时间
String timeConversion(String time) {
  DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(int.parse(time));
  return DateFormat("yyyy-MM-dd").format(dateTime).toString();
}

///复制到剪贴板
copy(String content) {
  Clipboard.setData(ClipboardData(text: content));
  toast("复制成功");
}

///朗读文本
ttf(String content) {
  FlutterPluginTts.speak(content);
}
